package com.incar.chuxing.baiduMap;

import android.content.Context;
import android.util.Log;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.Polygon;
import com.baidu.mapapi.map.PolygonOptions;
import com.baidu.mapapi.map.Polyline;
import com.baidu.mapapi.map.Stroke;
import com.baidu.mapapi.model.LatLng;
import com.incar.chuxing.bean.CityBoundBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Michael on 11/6.
 */

public class PolygonUtils {
    private Context mContext;
    private BaiduMap mBaiduMap;
    public List<Overlay> polygonBoundList = new ArrayList<>();
    public List<Overlay> polygonCoverList = new ArrayList<>();

    public PolygonUtils(BaiduMap mBaiduMap) {
        this.mBaiduMap = mBaiduMap;
    }


    public void clearCover() {
        if (polygonCoverList != null && polygonCoverList.size() != 0) {
            for (int i = 0; i < polygonCoverList.size(); i++) {
                polygonCoverList.get(0).remove();
            }
            polygonCoverList.clear();
        }
    }


    //行驶中添加围栏线
    public void addBounds(List<List<CityBoundBean.AttachmentBean>> allBoundsList) {
        if (allBoundsList != null && allBoundsList.size() != 0) {
            for (int i = 0; i < allBoundsList.size(); i++) {
                polygonBoundList.add(mBaiduMap.addOverlay(
                        new PolygonOptions()
                                .points(createBoundInDriving(allBoundsList.get(i)))
                                .stroke(new Stroke(6, 0xFFFF4C00))
                                .fillColor(0x00000000).zIndex(1)
                ));
            }

        }
    }


    private List<LatLng> createBoundInDriving(List<CityBoundBean.AttachmentBean> boundList) {
        List<LatLng> boundLstLngList = new ArrayList<>();
        for (int i = 0; i < boundList.size(); i++) {
            LatLng latLng = new LatLng(boundList.get(i).getLatitude(), boundList.get(i).getLongitude());
            boundLstLngList.add(latLng);
        }
        return boundLstLngList;
    }


    //行驶中添加围栏填充
    public void addBoundsCover(List<List<CityBoundBean.AttachmentBean>> allBoundsList) {
        for (int i = 0; i < allBoundsList.size(); i++) {
            polygonCoverList.add(mBaiduMap.addOverlay(new PolygonOptions()
                    .points(createBoundInDriving(allBoundsList.get(i)))
                    .stroke(new Stroke(0, 0x00000000))
                    .fillColor(0x33FA960A)
                    .zIndex(1)));
        }
    }
}